package threePart.exception;

public class TryCatchTest {
    public static void main(String[] args) {
        TryCatchTest tct = new TryCatchTest();
        /* int result = tct.test();
        System.out.println("test()方法执行完成后返回的值为：" + result);*/

        /* int result2 = tct.test2();
        System.out.println("我想大声告诉你！test2()返回的值：" + result2);*/
        int result3 = tct.test3();
        System.out.println("我想大声告诉你！test2()返回的值：" + result3);
    }

    public int test() {
        int divider = 10;
        int result = 100;

        try {
            while (divider > -1) {
                divider--;
                result = result + 100 / divider;
            }
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("循环抛出异常了！！！");
            return -1;
        }
    }

    public int test2() {
        int divider = 10;
        int result = 100;

        try {
            while (divider > -1) {
                divider--;
                result = result + 100 / divider;
            }
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("循环抛出异常了！！！");
            return 999;
        } finally {
            System.out.println("这是finally！！哈哈！！");
            System.out.println("我是result！！我的值是：" + result);
        }

    }

    public int test3() {
        int divider = 10;
        int result = 100;

        try {
            while (divider > -1) {
                divider--;
                result = result + 100 / divider;
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("循环抛出异常了！！！");
        } finally {
            System.out.println("这是finally！！哈哈！！");
            System.out.println("我是result！！我的值是：" + result);
            System.out.println("我是test3()！我运行完了！表想我！！！~~");
            return 1111;
        }
    }
}
